#!/usr/bin/env python
# -*- coding: utf-8 -*-

from os import sep
import pygame
from pygame.locals import *
from sys import exit
from submain import *

pygame.init()

pygame.display.set_caption("GunPy Battle")
icone = pygame.image.load('images'+sep+'icone.png')
pygame.display.set_icon(icone)
screensize = (900, 600)
screen = pygame.display.set_mode(screensize,0 ,32)

music = pygame.mixer.Sound('sounds'+sep+'menu_sound.wav')
botao_sound = pygame.mixer.Sound('sounds'+sep+'botao_sound.wav')
som = music.play(-1)

menu = pygame.image.load('images'+sep+'menus'+sep+'main.png').convert()
b_jogar = pygame.image.load('images'+sep+'botoes'+sep+'b_jogar.png').convert_alpha()
b_instrucoes = pygame.image.load('images'+sep+'botoes'+sep+'b_instrucoes.png').convert_alpha()
b_creditos = pygame.image.load('images'+sep+'botoes'+sep+'b_creditos.png').convert_alpha()
b_jogar_press = pygame.image.load('images'+sep+'botoes'+sep+'b_jogar_press.png').convert_alpha()
b_instrucoes_press = pygame.image.load('images'+sep+'botoes'+sep+'b_instrucoes_press.png').convert_alpha()
b_creditos_press = pygame.image.load('images'+sep+'botoes'+sep+'b_creditos_press.png').convert_alpha()

# VALOR INICIAL DE ALTURA
y = 290

x_botoes = screensize[0]/2 - b_jogar.get_width()/2
y_jogar = y + 58*0
y_instrucoes = y + 58*1
y_creditos = y + 58*2

clock = pygame.time.Clock()

bt_jogar = b_jogar
bt_instrucoes = b_instrucoes
bt_creditos = b_creditos

while True:
    pressed_mouse = pygame.mouse.get_pressed()
    pos_mouse = pygame.mouse.get_pos()
    
    for event in pygame.event.get():
        if event.type==QUIT:
            exit()
            
        if event.type == MOUSEBUTTONDOWN and event.button == 1:
            if is_over(event.pos, b_jogar, (x_botoes, y_jogar), True, botao_sound):
                jogar(music)
                music.play(-1)
            elif is_over(event.pos, b_instrucoes, (x_botoes, y_instrucoes), True, botao_sound):
                instrucoes()
            elif is_over(event.pos, b_creditos, (x_botoes, y_creditos), True, botao_sound):
                creditos()
                
        if event.type == MOUSEMOTION:
            if is_over(event.pos, b_jogar, (x_botoes, y_jogar)):
                bt_jogar = b_jogar_press
            else:
                bt_jogar = b_jogar
                
            if is_over(event.pos, b_instrucoes, (x_botoes, y_instrucoes)):
                bt_instrucoes = b_instrucoes_press
            else:
                bt_instrucoes = b_instrucoes
                
            if is_over(event.pos, b_creditos, (x_botoes, y_creditos)):
                bt_creditos = b_creditos_press
            else:
                bt_creditos = b_creditos
    
    clock.tick(40)
    
    screen.blit(menu, (0,0)) 
    screen.blit(bt_jogar, (x_botoes,y_jogar))
    screen.blit(bt_instrucoes, (x_botoes,y_instrucoes))
    screen.blit(bt_creditos, (x_botoes,y_creditos))

    pygame.display.update()